#include "p2p.h"
/**TESTING MODULE For Kevin**/

void test (struct list listInitialPeers, struct list listLocalFiles) {
  if (listInitialPeers.size > 0) {
      //Print all peers specified on command line.
      printf("Peer List SIZE: %d\n", listInitialPeers.size);
      printInitialPeers (listInitialPeers);
  }
  
  //Print list of local Files (Command Line Argument)
  if (listLocalFiles.size > 0){
    printf("Local File List SIZE: %d\n", listLocalFiles.size);

    struct node * itFiles = createIterator(listLocalFiles);
  
    while (hasNext(itFiles)){
      next(&itFiles);      
      printf("%s\n", (char *)(itFiles->payload));
    } 
    
    printf("\n");
  }
  
  //Test time function
  push (&outstandingRequestsList, createOutstandingReqItem("Outstanding Node 1",0));
  //Test time function
  push (&outstandingRequestsList, createOutstandingReqItem("Outstanding Node 2",0));
  //Test time function
  push (&outstandingRequestsList, createOutstandingReqItem("Outstanding Node 3",0));
  
  //Test Search through local file directory
  searchList( &listLocalFiles, "test.txt", 0);
  
  
  char buffer[3];
  buffer[0] = 0x65;
  buffer[1] = 0x64;
  buffer[2] = 0x00;
  
  struct node * dc1 = createCacheItem("test1.txt", buffer, 3);
  struct node * dc2 = createCacheItem("test2.txt", buffer, 3);
  struct node * dc3 = createCacheItem("test3.txt", buffer, 3);
  
  push(&dataCacheList, dc1);
  printf("DATACACHE LIST SIZE: %d\n", dataCacheList.size);

  push(&dataCacheList, dc2);
  printf("DATACACHE LIST SIZE: %d\n", dataCacheList.size);

  push(&dataCacheList, dc3);
  printf("DATACACHE LIST SIZE: %d\n", dataCacheList.size);
  
  
  struct addressPort peer1 = {2130706433, 3333};
  struct addressPort peer2 = {2130706433, 3333};
  struct addressPort peer3 = {2130706433, 4444};
  struct addressPort peer4 = {2130706433, 5555};
  
  struct node * cd1 = createContentDirItem ("cd1.txt", peer1);
  struct node * cd2 = createContentDirItem ("cd2.txt", peer2);
  struct node * cd3 = createContentDirItem ("cd3.txt", peer3);
  struct node * cd4 = createContentDirItem ("cd4.txt", peer4);
  
  push(&contentDirectoryList, cd1);
  push(&contentDirectoryList, cd2);
  push(&contentDirectoryList, cd3);
  push(&contentDirectoryList, cd4);
  printf("CONTENT DIRECTORY SIZE: %d\n", contentDirectoryList.size);
  
  
  //Test search through data cache
  searchList( &dataCacheList, "test2.txt", 1);

   //Print dataCache list
  struct node * itDataCache = createIterator(dataCacheList);
  struct dataCache * tempDataCache;
  
  while (hasNext(itDataCache)){
    next(&itDataCache);
    tempDataCache = (struct dataCache *) (itDataCache->payload);
    printf("DATACACHE NAMES: %s\n", tempDataCache->name);
  }
  
  char requestMessageBufferTemp[MAX_MSG];
  int msgLen = createRequestMessage("edo", requestMessageBufferTemp);
  printf("REQ MSG LENGTH: %d\n", msgLen);
  
  threadListingMessage();
  checkRequests();
  
} // End Test